# Definition for a binary tree node.
class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

class Solution(object):
    def sortedArrayToBST(self, nums):
        """
        :type nums: List[int]
        :rtype: TreeNode
        """
        nums_len = len(nums)
        if nums_len == 0:
            return None
        if nums_len == 1:
            return TreeNode(val=nums[0], left=None, right=None)
        mid_index = int(nums_len/2)
        left_node = self.sortedArrayToBST(nums[:mid_index])
        right_node = self.sortedArrayToBST(nums[mid_index+1:])
        return TreeNode(val=nums[mid_index], left=left_node, right=right_node)
